#! /bin/sh
root_dir="$(cd "$(dirname "$0")" && pwd)"

function process() {
  root=$1
  # echo $root
  for dir in $root; do
    dir=${dir%*/}         # remove the trailing "/"
    #echo "${dir##*/}"    # print everything after the final "/"

    if [[ "${dir: -4}" == ".git" ]]; then
      echo refreshing $dir
      git -C $dir fetch --quiet
    else
      if [[ "${dir: -5}" == "onehr" ]]; then
        echo skipping onehr repos as those are handled by push events
      else
        process "$dir/*"
      fi
    fi
  done
}

process "$root_dir/cache/*"